<template>
  <div>
    <Checkbox v-model="status.check" @on-change="checkAllNodes">全选</Checkbox>
    <Checkbox v-model="status.expand" @on-change="expandAll">展开</Checkbox>
    <div class="db_inline fr">
      <RadioGroup v-model="scope" @on-change="scopeChange">
        <Radio label="p">PC</Radio>
        <Radio label="w">微信</Radio>
      </RadioGroup>
    </div>
    <div id="menuTree" class="ztree tree">

    </div>

  </div>
</template>

<script>
  import $ from 'jquery';
  import 'ztree';
  import 'ztree/css/metroStyle/metroStyle.css';


  export default {
    name: "Ztree",
    props: {
      nodeData: {
        type: Array,
      },

    },
    data() {
      return {
        status: {
          check: false,
          expand: false
        },
        scope:'p',
        ztree: null,
        setting: {
          view: {
            showLine: true
          },
          treeNode: {
            open: true
          },
          data: {
            key: {
              name: 'title'
            },
            simpleData: {
              enable: true
            }
          },
          check: {
            enable: true,
            chkStyle: 'checkbox',
            chkboxType: {"Y": "p", "N": "ps"}
          },
          callback: {}
        }
      }
    },
    methods: {
      initScope(){
        this.scope='p'
      },
      scopeChange(scope){
        this.$emit('scope-change',scope)
      },
      getChecked() {
        return this.ztree.getCheckedNodes();
      },
      checkAllNodes(check) {
        this.status.check=check;
        this.ztree.checkAllNodes(check);
      },
      expandAll(expand) {
        this.status.expand=expand;
        this.ztree.expandAll(expand);
      }
    },
    watch: {
      nodeData: {
        handler(newData, oldData) {
          this.ztree = $.fn.zTree.init($("#menuTree"), this.setting, newData);
        },
        immediate: true,
      }
    },
    mounted() {

    }
  }
</script>

<style scoped>
  .tree {
    margin: 10px 0 0 0;
  }
</style>
